package com.example.spring_boot_service.service;

import com.example.spring_boot_service.entity.User;
import com.example.spring_boot_service.excepetion.ServiceException;
import com.example.spring_boot_service.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class UserService {
    @Resource
    UserMapper userMapper;
    public List<User> selectUser(User user){
        return userMapper.userSelect(user);
    }

    public User  login(User user) {
         User dbUser = userMapper.selectByUserName(user.getUsername());
         if(dbUser == null ){
            throw  new ServiceException("账号或密码输入错误");
         }
         if(!Objects.equals(dbUser.getPassword(), user.getPassword())){
             throw  new ServiceException("账号或密码输入错误");
         }
        return dbUser;
    }
}
